Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return the result of the callback in the promise #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

georgehb
Copy link

This makes the promise returned by wait-for-expect resolve to the same value returned by the supplied callback

This would allow you to do something like this without having to repeat the call to getNumber:

const value = await waitForExpect(async() => {
    const val = await getNumber() // returns some number that might/should be greater than 50
    expect(val).toBeGreaterThan(50)
    return val
})
console.log(value > 50) // true
// Do something with value

My motivation for this is for use in the pptr-testing-library where it's wait function is (more or less) an alias for waitForExpect. In short I often want to wait for an element to exist on the page and then do something with the element. ie what I would like to do is this

const $button = await wait(() => $document.getByRole("button"))
// Do something with $button ...

@sadams
Copy link

sadams commented Sep 13, 2024

@georgehb i know it's been a while but if you are interested i merged your PR on my fork of this project: #39 (comment)
Hope you don't mind!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants